home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / cimb.arj / ERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-04  |  6.0 KB  |  268 lines

  1. /*==============================================================================
  2.  
  3. FICHERO: ERROR.C
  4.  
  5. AUTOR: ANTONIO LADESA JURADO
  6.  
  7. FECHA: 24/6/94
  8.  
  9. DESCRIPCION:
  10.  
  11.     Fichero que contiene las estructuras, constantes, variables y funciones
  12.     internas y externas para el manejo de errores
  13.  
  14. ==============================================================================*/
  15.  
  16.  
  17. /*---- MODULOS USADOS --------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <conio.h>
  21. #include <dos.h>
  22. #include <dir.h>
  23.  
  24. #include "error.h"
  25. #include "menu.h"
  26. #include "teclas.h"
  27. #include "raton.h"
  28.  
  29. /*---- ESTRUCTURAS, CONSTANTES Y VARIABLES LOCALES AL MODULO -----------------*/
  30.  
  31.     /* respuestas al error hardware */
  32. #define IGNORAR  0
  33. #define REINTENTAR   1
  34. #define ANULAR   2
  35.  
  36.     /* error software actual */
  37. static ERROR ERRORsoftware;
  38.  
  39. /* definicion de los mensajes de error para atrapar problemas de disco */
  40. static char *errores_hardware[] =
  41.     {
  42.     "Disco protegido",
  43.     "Unidad desconocida",
  44.     "Unidad no preparada",
  45.     "Comando desconocido",
  46.     "Error de datos (CRC)",
  47.     "Respuesta erronea",
  48.     "Error de posicion",
  49.     "Medio desconocido",
  50.     "Sector no encontrado",
  51.     "Impresora sin papel",
  52.     "Error de escritura",
  53.     "Error de lectura",
  54.     "Fallo general",
  55.     "Reservado",
  56.     "Reservado",
  57.     "Cambio de disco erroneo"
  58.     };
  59.  
  60.     /* definición de los mensajes de error dados por el programa */
  61. static char *errores_software[] =
  62.     {
  63.     "",
  64.     "No hay imagen cargada",
  65.     "No hay memoria",
  66.     "Leyendo fichero",
  67.     "Escribiendo fichero",
  68.     "Abriendo fichero",
  69.     "Formato no tratado",
  70.     "Formatos incompatibles",
  71.     "La imagen es monocromatica",
  72.     "La imagen no es monocromatica",
  73.     "Imagen demasiado grande",
  74.     "Imposible escalar más",
  75.     "Impresora no preparada",
  76.     "Imposible borrar fichero",
  77.     "Imposible renombrar fichero",
  78.     "Ratón no instalado",
  79.     };
  80.  
  81. /*---- DEFINICION DE LAS FUNCIONES INTERNAS ----------------------------------*/
  82.  
  83. int leer_respuesta(char *msg);
  84. int manejador(int errval,int ax,int bp,int si);
  85.  
  86. /*---- CODIFICACION DE LAS FUNCIONES OFRECIDAS -------------------------------*/
  87.  
  88. /*---- FUNCION: extern void ERRORmanejador(void) -------------------------------
  89.  
  90.     Descripción:
  91.  
  92.         Esta función instala el manejador de errores de hardware para
  93.         tratar errores del disco, fundamentalmente
  94.  
  95. ---- CODIGO: -----------------------------------------------------------------*/
  96.  
  97. extern void ERRORmanejador(void)
  98. {
  99. harderr(manejador);
  100. }
  101.  
  102. /*---- FIN FUNCION -----------------------------------------------------------*/
  103.  
  104. /*---- FUNCION: extern int ERRORponer(int error) -------------------------------
  105.  
  106.     Descripción:
  107.  
  108.         Esta función establece un error del programa, actualizando la variable
  109.         ERRORsoftware
  110.  
  111.     Parámetros:
  112.  
  113.         int error: código de error
  114.  
  115.     Retorno:
  116.  
  117.         Código del error
  118.  
  119. ---- CODIGO: -----------------------------------------------------------------*/
  120.  
  121. extern int ERRORponer(int error)
  122. {
  123. return(ERRORsoftware = error);
  124. }
  125.  
  126. /*---- FIN FUNCION -----------------------------------------------------------*/
  127.  
  128. /*---- FUNCION: extern int ERRORver(void) --------------------------------------
  129.  
  130.     Descripción:
  131.  
  132.         Esta función visualiza un error y lo elimina tras la lectura de un
  133.         evento
  134.  
  135.     Retorno:
  136.  
  137.         ERRno
  138.  
  139. ---- CODIGO: -----------------------------------------------------------------*/
  140.  
  141. extern int ERRORver(void)
  142. {
  143. char msg[128];
  144. struct EVENTO evento;
  145. if(ERRORsoftware)
  146.     {
  147.     sprintf(msg,"Error:%s",errores_software[ERRORsoftware]);
  148.     putch(7);
  149.     ESTADOponer(msg);
  150.     do
  151.         {
  152.         evento = leer_evento(evento);
  153.         }
  154.     while(evento.e == NO_EVENTO);
  155.     ESTADOquitar();
  156.     }
  157. return(ERRORsoftware = ERRno);
  158. }
  159.  
  160. /*---- FIN FUNCION -----------------------------------------------------------*/
  161.  
  162. /*---- CODIFICACION DE LAS FUNCIONES INTERNAS --------------------------------*/
  163.  
  164. /*---- FUNCION: int leer_respuesta(char *msg) ----------------------------------
  165.  
  166.     Descripción:
  167.  
  168.         Esta función lee una respuesta ante un error de dispositivo
  169.  
  170.     Parámetros:
  171.  
  172.         char *msg: mensaje de error
  173.  
  174.     Retorno:
  175.  
  176.         Respuesta: ANULAR, REINTENTAR o IGNORAR
  177.  
  178. ---- CODIGO: -----------------------------------------------------------------*/
  179.  
  180. int leer_respuesta(char *msg)
  181. {
  182. int respuesta;
  183. struct EVENTO evento;
  184.  
  185. ESTADOponer(msg);
  186.  
  187.     /* lectura de tecla para (a)bortar, (r)eintentar o (i)gnorar */
  188. while(1)
  189.     {
  190.     evento = leer_evento(evento);
  191.   ESTADOquitar();
  192.  
  193.     if(evento.e == RATON_IZDO_ON)
  194.         {
  195.         respuesta = REINTENTAR;break;
  196.         }
  197.     else if(evento.e == RATON_DCHO_ON)
  198.         {
  199.         respuesta = IGNORAR;break;
  200.         }
  201.  
  202.   respuesta = evento.e;
  203.     
  204.     if (respuesta == 'a' || respuesta == 'A')
  205.         {
  206.         respuesta = ANULAR;break;
  207.         }
  208.     if (respuesta == 'r' || respuesta == 'R')
  209.         {
  210.         respuesta = REINTENTAR;break;
  211.         }
  212.     if (respuesta == 'i' || respuesta == 'I')
  213.         {
  214.         respuesta = IGNORAR;break;
  215.         }
  216.     }
  217. return(respuesta);
  218. }
  219.  
  220. /*---- FIN FUNCION -----------------------------------------------------------*/
  221.  
  222. /*---- FUNCION: int manejador(int errval,int ax,int bp,int si) -----------------
  223.  
  224.     Descripción:
  225.  
  226.         Esta función es el manejador de errores de hardware para
  227.         tratar errores del disco, fundamentalmente
  228.  
  229.     Parámetros:
  230.  
  231.         int errval : código del error
  232.  
  233.         int ax :
  234.         int bp :
  235.         int si : registros del procesador implicados
  236.  
  237. ---- CODIGO: -----------------------------------------------------------------*/
  238.  
  239. int manejador(int errval,int ax,int bp,int si)
  240. {
  241. static char msg[128];
  242. unsigned di;
  243. int drive;
  244. int errorno;
  245.  
  246. di= _DI;
  247.  
  248.     /* Si no es un error de disco... */
  249. if(ax < 0)
  250.     {
  251.     leer_respuesta("Error de dispositivo");
  252.     hardretn(ANULAR);
  253.     }
  254.  
  255.     /* Si es error de disco */
  256. drive = ax & 0x00FF;
  257. errorno = di & 0x00FF;
  258. sprintf(msg,"Error: %s en unidad %c. A)bortar, R)eintentar, I)gnorar: ",
  259.     errores_hardware[errorno], 'A' + drive);
  260.  
  261.     /* retorna al programa por la interrupcion 0x23 con abortar, reintentar,
  262.         o ignorar segun responda del usuario. */
  263. hardresume(leer_respuesta(msg));
  264. return ANULAR;
  265. }
  266.  
  267. /*---- FIN FUNCION -----------------------------------------------------------*/
  268.